//
//  FZHomeStatusRetweetView.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/24/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit

class FZHomeStatusRetweetView: UIView {
    var status: FZHomeStatusViewModel?{
        didSet{
            
            if status != nil {
                contentLabel.text = status?.status?.retweeted_status?.text
                
                pictueView.pictureInfo = status?.status?.retweeted_status?.pic_urls
                
                pictueView.snp_updateConstraints(closure: { (make) in
                    
                    make.top.equalTo(contentLabel.snp_bottom).offset(PADDING)
                    make.bottom.equalTo(-PADDING)
                })
            }else{
                //没有值得时候，把contentelabel.text赋值为空，pictueView.pictureInfo赋值为nil
                contentLabel.text = ""
                pictueView.pictureInfo = nil
                pictueView.snp_updateConstraints(closure: { (make) in
                    
                    make.top.equalTo(contentLabel.snp_bottom).offset(0)
                    make.bottom.equalTo(PADDING)
                })
            }
            
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = TheTableColor
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        addSubview(contentLabel)
        addSubview(pictueView)
        setupLayout()
        
    }
    private func setupLayout() {
        
        contentLabel.snp_makeConstraints { (make) in
            
            make.leading.trailing.equalTo(0)
            make.top.equalTo(PADDING)
            
        }
        pictueView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp_bottom).offset(PADDING)
            make.leading.equalTo(contentLabel.snp_leading)
            make.bottom.equalTo(0)
            
        }
    }
    
   private lazy var contentLabel = UILabel(textColor: UIColor.grayColor(), textFont: 13, width: SCREENW - 2 * PADDING)
    //图片
    private lazy var pictueView: FZHomeStatusPictureView = {
        let flowlayout = UICollectionViewFlowLayout()
        let vi: FZHomeStatusPictureView = FZHomeStatusPictureView(frame: CGRectZero, collectionViewLayout: flowlayout)
        return vi
    }()
}
